home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / misc / gnupl_test < prev    next >
Text File  |  1995-10-16  |  6KB  |  290 lines

  1.  #
  2.  # Test 2-D plots
  3.  #
  4.  
  5.  printf (" Have you got a gnuplot-3.5 patched with multiplot and border? (y/n) (def. no) ");
  6.  ans = getline ("stdin");
  7.  
  8.  x = (0.25:4:.25)';
  9.  
  10.  //-----------------------------------------------------------------//
  11.  autoscale();
  12.  title ("Multiple Line Colors and Styles");
  13.  linestyle ("line");
  14.  nogrid();
  15.  xlabel ("X-axis Label");
  16.  ylabel ("Y-axis Label");
  17.  plot ( [x, x, 2*x, 3*x] );
  18.  pause ("Type RETURN to continue");
  19.  
  20.  title ("Multiple Point Colors and Styles");
  21.  linestyle ("point");
  22.  nogrid();
  23.  plot ( [x, x, 2*x, 3*x] );
  24.  pause ("Type RETURN to continue");
  25.  
  26.  title ("Multiple Line-Point Colors and Styles");
  27.  linestyle ("linespoint");
  28.  grid();
  29.  plot ( [x, x, 2*x, 3*x] );
  30.  pause ("Type RETURN to continue");
  31.  
  32.  title ("Multiple Line-Point Colors and Styles");
  33.  linestyle ("lines");
  34.  nogrid();
  35.  plot ( [x, x] );
  36.  linestyle ("point");
  37.  replot ( [x, 2*x] );
  38.  linestyle ("linespoint");
  39.  replot ( [x, 3*x] );
  40.  pause ("Type RETURN to continue");
  41.  
  42.  nogrid();
  43.  //-----------------------------------------------------------------//
  44.  # Show off axis types
  45.  title("Linear Axes");
  46.  grid();
  47.  nolog();
  48.  plot ([x,exp(-x*0.5)]);
  49.  pause ("Type RETURN to continue");
  50.  
  51.  title("Log X - Axis");
  52.  grid();
  53.  semilogx();
  54.  plot ([x,exp(-x*0.5)]);
  55.  pause ("Type RETURN to continue");
  56.  
  57.  title("Log Y - Axis");
  58.  grid();
  59.  semilogy();
  60.  plot ([x,exp(-x*0.5)]);
  61.  pause ("Type RETURN to continue");
  62.  
  63.  title("Log  Axes");
  64.  loglog();
  65.  grid();
  66.  plot ([x,exp(-x*0.5)]);
  67.  pause ("Type RETURN to continue");
  68.  
  69.  nolog();
  70.  nogrid();
  71.  
  72.  //-----------------------------------------------------------------//
  73.  # Data with different scales
  74. // y = (0.5:6:.2)';
  75. // title("Plot Data with Different Scales");
  76. // grid();
  77. // plot (<< [x,exp(-x*0.5)] ; [y, exp (y*0.25), exp(y*0.1)] >>);
  78. //pause ("Type RETURN to continue");
  79.  
  80.  # Histograms
  81.  
  82.  rand("normal", 0, pi);
  83.  r = rand(2000,1);
  84.  
  85.  nogrid();
  86.  linestyle("boxes");
  87.  title("Histogram, Default No. of Bins");
  88.  hist (r);
  89.  pause ("Type RETURN to continue");
  90.  
  91.  
  92.  title("Histogram, 30 Bins");
  93.  nogrid();
  94.  hist (r, 30);
  95.  pause ("Type RETURN to continue");
  96.  
  97.  title("2 Histograms, 30 Bins");
  98.  nogrid();
  99.  hist ([r, 2*r], 30);
  100.  pause ("Type RETURN to continue");
  101.  
  102.  linestyle("lines");
  103.  title("2 Histograms, 30 Bins");
  104.  nogrid();
  105.  hist ([r, 2*r], 30);
  106.  pause ("Type RETURN to continue");
  107.  autoscale();
  108.  
  109.  //-----------------------------------------------------------------//
  110.  # Make 3D data
  111.  
  112.  # Sombrero
  113.  
  114.  NX = 20;
  115.  NY = 20;
  116.  xx = zeros (1, NX);
  117.  yy = zeros (1, NY);
  118.  for (i in 1:NX) { xx[i] = (i - NX/2)/(NX/2); }
  119.  for (i in 1:NY) { yy[i] = (i - NY/2)/(NY/2); }
  120.  
  121.  zz = zeros (NX, NY);
  122.  
  123.  for (i in 1:NX)
  124.  {
  125.      for (j in 1:NY)
  126.      {
  127.      r = sqrt (xx[i]^2 + yy[j]^2);
  128.      zz[i;j] = exp (-r * r) * cos (2*pi*r);
  129.      }
  130.  }
  131.  
  132.  # Now create some plots
  133.  
  134.  title("3-D Plot, Sombrero");
  135.  grid();
  136.  splot(xx,yy,zz);
  137.  pause ("Type RETURN to continue");
  138.  
  139.  
  140.  # Sin - Cos surface
  141.  
  142.  x1 = -3:3:.2;
  143.  y1 = -3:3:.2;
  144.  z1 = zeros (x1.n, y1.n);
  145.  
  146.  for (i in 1:x1.n)
  147.  {
  148.      for(j in 1:y1.n)
  149.      {
  150.      z1[i;j] = sin(y1[j]) * cos(x1[i]);
  151.      }
  152.  }
  153.  
  154.  title("3-D Plot, Cos-Sine Surface");
  155.  nogrid();
  156.  splot(x1,y1,z1);
  157.  pause ("Type RETURN to continue");
  158.  
  159.  
  160.  # Slanted plane
  161.  
  162.  x2 = 1:10;
  163.  y2 = 1:10;
  164.  z2 = zeros (x2.n, y2.n);
  165.  for (i in 1:x2.n) { z2[i;] = i*ones(1,y2.n); }
  166.  
  167.  title("3-D Plot, Plane");
  168.  splot(x2,y2,z2);
  169.  pause ("Type RETURN to continue");
  170.  
  171.  
  172.  # Two Slanted planes
  173.  z3 = -2*z2;
  174.  title("3-D Plot, 2 - Planes");
  175.  splot(x2,y2,[z2',z3]);
  176.  pause ("Type RETURN to continue");
  177.  
  178.  
  179.  
  180.  //-----------------------------------------------------------------//
  181.  
  182.  #
  183.  # Simple contour plotting demonstration
  184.  #
  185.  
  186.  NX = 20;
  187.  NY = 20;
  188.  xx = zeros (1, NX);
  189.  yy = zeros (1, NY);
  190.  for (i in 1:NX) { xx[i] = (i - NX/2)/(NX/2); }
  191.  for (i in 1:NY) { yy[i] = (i - NY/2)/(NY/2); }
  192.  
  193.  zz = zeros (NX, NY);
  194.  
  195.  for (i in 1:NX)
  196.  {
  197.      for (j in 1:NY)
  198.      {
  199.      r = sqrt (xx[i]^2 + yy[j]^2);
  200.      zz[i;j] = exp (-r * r) * cos (2*pi*r);
  201.      }
  202.  }
  203.  
  204.  # Sin - Cos surface
  205.  
  206.  x1 = -3:3:.2;
  207.  y1 = -3:3:.2;
  208.  z1 = zeros (x1.n, y1.n);
  209.  
  210.  for (i in 1:x1.n)
  211.  {
  212.      for(j in 1:y1.n)
  213.      {
  214.      z1[i;j] = sin(y1[j]) * cos(x1[i]);
  215.      }
  216.  }
  217.  
  218.  # Now create some plots
  219.  
  220.  xlabel("X-Axis");
  221.  ylabel("Y-Axis");
  222.  title ("Contour Demonstration");
  223.  cont(xx,yy,zz);
  224.  pause ("Type RETURN to continue");
  225.  
  226.  xlabel("X-Axis");
  227.  ylabel("Y-Axis");
  228.  title ("Contour Demonstration");
  229.  cont (x1,y1,z1);
  230.  pause ("Type RETURN to continue");
  231.  
  232.  
  233.  //-----------------------------------------------------------------//
  234.  
  235.  #
  236.  # demonstrate replot, multiplot and plotyy.
  237.  #
  238.  
  239.  x=0:10:0.1;
  240.  m1=[x',sin(x)'];
  241.  m2=[x',(cos(x)+1)'];
  242.  
  243.  key();
  244.  title("a sin(x).");
  245.  plot(m1,["sin(x)"]);
  246.  pause("Type RETURN to continue");
  247.  
  248.  
  249.  title("cos(x)+1 added with a replot(data) command.");
  250.  replot(m2,["cos(x)+1"]);
  251.  pause("Type RETURN to continue");
  252.  
  253.  if (ans.[1] == "y" || ans.[1] == "Y") {
  254.      title("Plot with txo y-axes");
  255.      plotyy();
  256.      key();
  257.      linestyle("lines");
  258.      ylabel("sin(x)");
  259.      plot(m1,["sin(x)"]);
  260.      ylabel("cos(x)+1");
  261.      plot(m2,["cos(x)+1"]);
  262.      pause("Type RETURN to continue");
  263.      
  264.      nokey();
  265.      ylabel ("Y-axis");
  266.      multiplot(2,2);
  267.      linestyle("lines");
  268.      title("Sombrero");
  269.      splot(xx,yy,zz);
  270.      x = (0.25:4:.25)';
  271.      y = (0.5:6:.2)';
  272.      title("Different Scales");
  273.      grid();
  274.      plot (<< [x,exp(-x*0.5)] ; [y, exp (y*0.25), exp(y*0.1)] >>);
  275.      nogrid();
  276.      plotyy();
  277.      title("Plot with txo y-axes");
  278.      ylabel("sin(x)");
  279.      plot(m1);
  280.      ylabel("cos(x)+1");
  281.      plot(m2);
  282.      xlabel("");
  283.      ylabel("");
  284.      title("Contour plot");
  285.      cont(xx,yy,zz);
  286.      pause("Type RETURN to continue");
  287.      
  288.  }
  289.  pclose(0);
  290.